#!/bin/bash

set -ex 

sudo apt-get update
# apt-transport-https may be a dummy package; if so, you can skip that package
sudo apt-get install -y apt-transport-https ca-certificates curl

curl -fsSL https://pkgs.k8s.io/core:/stable:/v1.25/deb/Release.key | sudo gpg --dearmor -o /etc/apt/keyrings/kubernetes-apt-keyring.gpg

echo 'deb [signed-by=/etc/apt/keyrings/kubernetes-apt-keyring.gpg] https://pkgs.k8s.io/core:/stable:/v1.25/deb/ /' | sudo tee /etc/apt/sources.list.d/kubernetes.list

sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl

systemctl unmask kubelet
systemctl daemon-reload

systemctl restart kubelet

kubeadm config images pull --image-repository registry.aliyuncs.com/google_containers -v=5

ctr -n k8s.io images tag registry.aliyuncs.com/google_containers/pause:3.8 registry.k8s.io/pause:3.8

rm -rf /var/log/containers/*

kubeadm init  --image-repository registry.aliyuncs.com/google_containers --kubernetes-version=v1.25.16

mkdir -p /root/.kube/
cp /etc/kubernetes/admin.conf /root/.kube/config
